package com.itheima.exception;

import com.itheima.project.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler
    public Result handleException(MethodArgumentTypeMismatchException e){
        log.info("Program running exceptionc.... ", e);
        return Result.error("只能输入整数");
    }


    @ExceptionHandler
    public Result handleBussinessException(BusinessException e){
        log.error("程序运行出错啦 .... ", e);
        return Result.error(e.getMessage());
    }
    @ExceptionHandler
    public Result handleException(NumberFormatException e){
        log.info("Program running exceptionc.... ", e);
        return Result.error("只能输入整数");
    }
}
